
using System;
using System.Text;
using SpotifyGenNHibernate.CEN;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using SpotifyGenNHibernate.EN.Spotify;

namespace SpotifyGenNHibernate.CAD.Spotify
{
        public partial class CancionBibliotecaCAD : BasicCAD, ICancionBibliotecaCAD
        {
        public CancionBibliotecaCAD() : base ()
        {
        }

        public CancionBibliotecaCAD(ISession sessionAux) : base (sessionAux)
        {
        }



        public CancionBibliotecaEN ReadOIDDefault (int id)
        {
                CancionBibliotecaEN cancionBibliotecaEN = null;

                try
                {
                        SesssionInitializeTransaction ();
                        cancionBibliotecaEN = (CancionBibliotecaEN)session.Load (typeof(CancionBibliotecaEN),
                                id

                                );
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in CancionBibliotecaCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return cancionBibliotecaEN;
        }


        public int New_ (CancionBibliotecaEN cancionBiblioteca)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        if (cancionBiblioteca.Cancion != null) {
                                cancionBiblioteca.Cancion = (SpotifyGenNHibernate.EN.Spotify.CancionEN)session.Load (typeof(SpotifyGenNHibernate.EN.Spotify.CancionEN), cancionBiblioteca.Cancion.Id);
                        }
                        if (cancionBiblioteca.Usuario != null) {
                                cancionBiblioteca.Usuario = (SpotifyGenNHibernate.EN.Spotify.UsuarioEN)session.Load (typeof(SpotifyGenNHibernate.EN.Spotify.UsuarioEN), cancionBiblioteca.Usuario.Id);
                        }

                        session.Save (cancionBiblioteca);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in CancionBibliotecaCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return cancionBiblioteca.Id;
        }

        public void Destroy (int id)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        CancionBibliotecaEN cancionBibliotecaEN = (CancionBibliotecaEN)session.Load (typeof(CancionBibliotecaEN),
                                id

                                );
                        session.Delete (cancionBibliotecaEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in CancionBibliotecaCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }

        public System.Collections.Generic.IList<CancionBibliotecaEN> ConsultarDestacados (int p_oid)
        {
                System.Collections.Generic.IList<CancionBibliotecaEN> result = null;
                try
                {
                        SesssionInitializeTransaction ();
                        String sql = @"FROM CancionBibliotecaEN self ";
                        IQuery query = session.CreateQuery (sql);
                        result = query.List<CancionBibliotecaEN>();
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in CancionBibliotecaCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return result;
        }
        public System.Collections.Generic.IList<CancionBibliotecaEN> ConsultarArchivosLocales (int p_oid)
        {
                System.Collections.Generic.IList<CancionBibliotecaEN> result = null;
                try
                {
                        SesssionInitializeTransaction ();
                        String sql = @"FROM CancionBibliotecaEN self ";
                        IQuery query = session.CreateQuery (sql);
                        result = query.List<CancionBibliotecaEN>();
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in CancionBibliotecaCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return result;
        }
        }
}
